import { BaseWindow } from "../../../../../component/window/BaseWindow";
import { ILayer } from "../../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../../extend/language/Language";
import { ObjCreate } from "../../../common/ObjCreate";
import { GuildEliteGroupGroupPart } from "./GuildEliteGroupGroupPart";
import { GModuleEvent } from "../../../../mvc/GModuleEvent";
import { GuildEliteGroupRightPart } from "./GuildEliteGroupRightPart";
import { GlobalSkin } from "../../../../../component/skin/GlobalSkin";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { FilterConst } from "../../../../../component/gconst/FilterConst";
import { Global } from "../../../../../../com/gengine/global/Global";
import { LoaderHelp } from "../../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../../resource/ResFileConst";
import { DataEvent } from "../../../../events/DataEvent";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { EventName } from "../../../../mvc/EventName";
import { EliteTowerFloorData } from "../EliteTowerFloorData";
import { SGuildGroup } from "../../../../../../Message/Public/SGuildGroup";
import { Cache } from "../../../../cache/Cache";
import { GTabBar } from "../../../../../../com/mui/controls/GTabBar";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { SecTimerView } from "../../../common/SecTimerView";
type int = number;
//class GuildEliteGroupModule
    
    export  class GuildEliteGroupModule extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._tabData = [];
            this.setSize(745, 505);
            this.title = Language.getString(60650);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._tabBar = ObjCreate.createGTabBar(18, 34, this._tabData, 88, 22, this, this.onTabChangeHandler);
            this._tabBar.labelName = "name";
            this._groupPart = new GuildEliteGroupGroupPart();
            this._groupPart.x = 18;
            this._groupPart.y = 60;
            this._groupPart.addEventListener(GModuleEvent.GuildGroup_OpenGroupBtnClick, this.onOpenGroupBtnClickHandler);
            this.addChild(this._groupPart);
            this._rightPart = new GuildEliteGroupRightPart();
            this._rightPart.x = 518;
            this._rightPart.y = 60;
            this.addChild(this._rightPart);
            this._leftBtn = ObjCreate.createGButton(Language.getString(60662), 40, 460, 80, 28, this, GlobalSkin.ButtonRed);
            this._leftBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClickHandler);
            this._enterBtn = ObjCreate.createGButton(Language.getString(60665), 130, 460, 80, 28, this, GlobalSkin.ButtonRed);
            this._enterBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClickHandler);
            this._tipText = ObjCreate.createSecTimeView("", 220, 468, 400, 20, this, GlobalStyle.textFormat5);
            this._tipText.filters = [FilterConst.glowFilter];
            if (Global.isDebugModle) 
            {
                this._disbandBtn = ObjCreate.createGButton(Language.getString(60664), 300, 460, 80, 28, this, GlobalSkin.ButtonRed);
                this._disbandBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClickHandler);
            }
            LoaderHelp.addResCallBack(ResFileConst.GuildGroup, this.onResLoaded);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            if (this._groupPart) 
            {
                this._groupPart.onResLoaded();
            }
            if (this._rightPart) 
            {
                this._rightPart.onResLoaded();
            }
            return;
        }

        /* internal  */onTabChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.updateData(this.selectedFloor);
            this.dispatchEvent(new DataEvent(GModuleEvent.GuildGroup_FloorSelectedChange, this.selectedFloor));
            return;
        }

        /* internal  */onOpenGroupBtnClickHandler(arg1: DataEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEliteGroup_DoOpenGroup, this.selectedCopy));
            return;
        }

        /* internal  */onButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target;
            switch (loc1) 
            {
                case this._enterBtn:
                {
                    if (this._inPreTime) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildElite_DoOpenGuildEliteCopy));
                    }
                    else 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildElite_DoEnterGuildEliteCopy, this._floorData));
                    }
                    break;
                }
                case this._leftBtn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEliteGroup_LeftGroup, this._floorData));
                    break;
                }
                case this._disbandBtn:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildEliteGroup_DisbandGroup, this._floorData));
                    break;
                }
            }
            return;
        }

        public get selectedCopy(): int
        {
            if (this.selectedFloor) 
            {
                return this.selectedFloor.copyCode;
            }
            return 0;
        }

        public get selectedFloor(): EliteTowerFloorData
        {
            return this._tabBar.selectedItem as EliteTowerFloorData;
        }

        public set selectedFloor(arg1: EliteTowerFloorData)
        {
            this._tabBar.selectedIndex = this._tabBar.dataProvider.indexOf(arg1);
            this.updateData(arg1);
            return;
        }

        public updateGroupData(arg1: SGuildGroup, arg2: Map<any, any> /* flash.utils.Dictionary */): void
        {
            if (arg1 == null) 
            {
                this._groupPart.group = null;
                this._groupPart.updateData(null);
                return;
            }
            if (this.selectedFloor && this.selectedFloor.copyCode == arg1.copyCode) 
            {
                this._groupPart.group = arg1;
                this._groupPart.updateData(arg2);
            }
            return;
        }

        public updateButtonState(arg1: Boolean, arg2: int): void
        {
            this._inPreTime = arg1;
            if (this._inPreTime) 
            {
                this._enterBtn.label = Language.getString(60666);
                this._tipText.setParse(Language.getString(60688));
                this._tipText.setLeftTime(arg2);
                this._rightPart.updatePreLeftTime(arg2);
            }
            else 
            {
                this._enterBtn.label = Language.getString(60665);
                this._tipText.stop();
                this._tipText.htmlText = Language.getString(60676);
            }
            return;
        }

        public updateGroupCommander(arg1: string): void
        {
            this._groupPart.updateCommander(arg1);
            return;
        }

        public updateData(arg1: EliteTowerFloorData): void
        {
            if (this.selectedFloor && this.selectedFloor.copyCode == arg1.copyCode) 
            {
                this._floorData = arg1;
                this._rightPart.updateFloor(this._floorData.floor);
                this._rightPart.updateMapsStatus(this._floorData.maps);
                this._rightPart.updateRewards(this._floorData.rewardItems);
                this._rightPart.updatePlayerNum(Cache.instance.guildElite.getPlayerNumByCopycode(this._floorData.copyCode), this._floorData.maxPlayerNum);
            }
            return;
        }

        public updateTabData(arg1: Array<any>): void
        {
            this._tabData = arg1;
            this._tabBar.dataProvider = this._tabData;
            this._tabBar.invalidate();
            return;
        }

        public updateLeftTime(arg1: int): void
        {
            this._rightPart.updateLeftTime(arg1);
            return;
        }

        public updatePlayerNum(arg1: int, arg2: int): void
        {
            this._rightPart.updatePlayerNum(arg1, arg2);
            return;
        }

        /* internal */ /* var */_floorData: EliteTowerFloorData;

        /* internal */ /* var */_tabData: Array<any>;

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_groupPart: GuildEliteGroupGroupPart;

        /* internal */ /* var */_rightPart: GuildEliteGroupRightPart;

        /* internal */ /* var */_enterBtn: GButton;

        /* internal */ /* var */_leftBtn: GButton;

        /* internal */ /* var */_disbandBtn: GButton;

        /* internal */ /* var */_tipText: SecTimerView;

        /* internal */ /* var */_inPreTime: Boolean=false;
    }
